package com.cci.kangdao.wechatOrder.dao;

import com.cci.kangdao.wechatOrder.model.UserOutSideTokenT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

/**
 * @description: 外部用户TOKEN记录表DAO
 * @author: zyf
 * @create: 2021-03-25
 */
@MapperScan
public interface UserOutSideTokenTDao {

    /**
     * 根据外部ID与token查询
     *
     * @param outSideID
     * @param token
     * @return
     */
    @Select("select * from UserOutSideToken_T where Token = #{token} and OutSideID = #{outSideID} and Flag =0")
    UserOutSideTokenT selectByToken(@Param("outSideID") String outSideID, @Param("token") String token);

    /**
     * 根据outSideID查询数据
     * @param outSideID
     * @return
     */
//    @Select("select * from UserOutSideToken_T where OutSideID = #{outSideID} and Flag =0")
//    UserOutSideTokenT selectByOutSideId(@Param("outSideID") String outSideID);


    /**
     * 根据outSideID查询数据
     *
     * @param outSideID
     * @return
     */
    @Select("select * from UserOutSideToken_T where OutSideID = #{outSideID} and Flag =0 and CompanyID=#{companyID}")
    UserOutSideTokenT selectByOutSideIdAndCompanyId(@Param("outSideID") String outSideID, @Param("companyID") Long companyID);

    /**
     * 查询用户外键ID并根据ID
     *
     * @param outSideID
     * @param flag
     * @return
     */
    @Select("select * from UserOutSideToken_T where OutSideID = #{outSideID} and Flag =#{flag}")
    UserOutSideTokenT selectByOutSideIdAndFlag(@Param("outSideID") String outSideID, @Param("flag") Integer flag);

    UserOutSideTokenT selectByOutSideIdAndUserId(@Param("outSideID") String outSideID, @Param("userId") Long userId, @Param("companyID") Long companyID);

    /**
     * 插入数据
     * @param tokenT
     * @return
     */
    int insert(UserOutSideTokenT tokenT);

    /**
     *
     * @param tokenT
     * @return
     */
    int updateTokenByOutSideId(UserOutSideTokenT tokenT);

    /**
     * 根据外键ID更新数据内容
     * @param tokenT
     * @return
     */
    int updateTokenAndUserIdByOutSideId(UserOutSideTokenT tokenT);

    /**
     * 更新openId根据用户ID与token
     *
     * @param tokenT
     * @return
     */
    int updateOutSideIDByTokenAndUserId(UserOutSideTokenT tokenT);


    int updateDeleteFlag(@Param("id") Long id);


}
